#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
int
main(int argc, char **argv)
{

    struct rusage buf;

    
    if(argc == 2) {
      system(argv[1]);
    }else {
      fprintf(stderr,"./getrusage  \"ls -l > /dev/null\"\n");
      exit(0);
    }
    int err = getrusage(RUSAGE_CHILDREN, &buf);
    //int err = getrusage(RUSAGE_SELF, &buf);
    printf("ERR=%d\n", err);
    printf("%20s:%ld/%ld\t%s\n", "ru_utime", 
       buf.ru_utime.tv_sec, buf.ru_utime.tv_usec,
       "user time used (secs/usecs)");
    printf("%20s:%ld/%ld\t%s\n", "ru_stime", 
       buf.ru_stime.tv_sec, 
       buf.ru_stime.tv_usec,
       "system time used (secs/usecs)");
    printf("%20s:%-10ld\t%s\n", 
       "ru_maxrss",
       buf.ru_maxrss,
       "maximum resident set size");
    printf("%20s:%-10ld\t%s\n",
       "ru_ixrss", 
       buf.ru_ixrss,
       "integral shared memory size");
    printf("%20s:%-10ld\t%s\n", 
       "ru_idrss",
       buf.ru_idrss,
       "integral unshared data size");
    printf("%20s:%-10ld\t%s\n", 
       "ru_isrss",
       buf.ru_isrss,
       "integral unshared data stack size");
    printf("%20s:%-10ld\t%s\n", 
       "ru_minflt",
       buf.ru_minflt,
       "page reclaims");
    printf("%20s:%-10ld\t%s\n",
       "ru_majflt",
       buf.ru_majflt,
       "page faults");
    printf("%20s:%-10ld\t%s\n",
       "ru_nswap",
       buf.ru_nswap,
       "swaps");
    printf("%20s:%-10ld\t%s\n",
       "ru_inblock",
       buf.ru_inblock,
       "block input operations");
    printf("%20s:%-10ld\t%s\n",
       "ru_oublock",
       buf.ru_oublock,
       "block output operations");
    printf("%20s:%-10ld\t%s\n",
       "ru_msgsnd",
       buf.ru_msgsnd,
       "messages sent");
    printf("%20s:%-10ld\t%s\n",
       "ru_msgrcv",
       buf.ru_msgrcv,
       "messages received");
    printf("%20s:%-10ld\t%s\n",
       "ru_nsignals",
       buf.ru_nsignals,
       "signals received");
    printf("%20s:%-10ld\t%s\n",
       "ru_nvcsw",
       buf.ru_nvcsw,
       "voluntary context switches");
    printf("%20s:%-10ld\t%s\n",
       "ru_nivcsw",
       buf.ru_nivcsw,
       "involuntary context switches");
  exit(0);
}
